package com.thinvent.recommend.common.enums;

/**
 * 用户推荐行为类型枚举（基于这五种类型来推荐）：
 * 0：点赞
 * 1：下载
 * 2：预览
 * 3：编辑
 * 4：收藏
 */
public enum UserBehaviorTypeEnums {

    LIKE      ("0", "点赞"),
    DOWNLOAD  ("1", "下载"),
    PREVIEW   ("2", "预览"),
    EDIT      ("3", "编辑"),
    FAVORITE  ("4", "收藏");

    private final String code;
    private final String description;

    UserBehaviorTypeEnums(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /** 返回枚举对应的代码值 */
    public String getCode() {
        return code;
    }

    /** 返回枚举的中文描述 */
    public String getDescription() {
        return description;
    }

    /**
     * 根据 code 获取枚举实例
     * @param code 行为类型代码
     * @return 对应的 UserBehaviorTypeEnums
     * @throws IllegalArgumentException 若 code 无效
     */
    public static UserBehaviorTypeEnums fromCode(String code) {
        for (UserBehaviorTypeEnums type : values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown UserBehaviorTypeEnums code: " + code);
    }

    @Override
    public String toString() {
        return code + " - " + description;
    }
}
